<?php
namespace app\admin\controller;
use app\admin\controller\Common;
use think\Db;
use app\common\model\Blh as BlhModel;
use think\Request;


class Blh extends Common{
    public $blh;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $blh=new BlhModel();
        $this->blh=$blh;
    }

    public function goods(){
        $shopId = session('shop_id');

        $filter = input('filter');
        if (!$filter || !in_array($filter, array(1, 2, 3))) {
            $filter = 3;
        }

        $where              = array();
        $where['a.shop_id'] = $shopId;
        switch ($filter) {
            case 1:
                $where['a.onsale'] = 1;
                break;
            case 2:
                $where['a.onsale'] = 0;
                break;
            case 3:

                break;
        }

        $list     = Db::name('goods')
            ->alias('a')
            ->field('a.id,a.goods_name,a.thumb_url,a.market_price,a.shop_price,a.onsale,a.is_live,b.cate_name')
            ->join('sp_category b', 'a.cate_id = b.id', 'LEFT')
            ->where($where)
            ->where('a.is_recycle', 0)
            ->order('a.addtime desc')
            ->paginate(25);
        $page     = $list->render();
        $cateres  = Db::name('category')->field('id,cate_name,pid')->order('sort asc')->select();
        $brandres = Db::name('brand')->field('id,brand_name')->select();

        if (input('page')) {
            $pnum = input('page');
        } else {
            $pnum = 1;
        }

        $this->assign('list', $list);
        $this->assign('page', $page);
        $this->assign('pnum', $pnum);
        $this->assign('filter', $filter);
        $this->assign('cateres', recursive($cateres));
        $this->assign('brandres', $brandres);
        if (request()->isAjax()) {
            return $this->fetch('ajaxpage');
        } else {
            return $this->fetch('lst');
        }
        return $this->fetch();
    }

    public function cate(){
        return $this->fetch();
    }

    public function getCate(){
        return $this->fetch();
    }

    public function brand(){
        return $this->fetch();
    }

    public function getBrand(){
        return $this->fetch();
    }

    public function getLocation(){
        return $this->fetch();
    }

}
